<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>

<%@ include file="../include.jsp"%>
<style>
.site-block {
	padding: 20px;
	border: 1px solid #eee;
}

.site-text {
	position: relative;
}
</style>
<div class="site-block site-text">
	<form class="layui-form" action="">
		<div class="layui-form-item">
			<label class="layui-form-label">教师姓名</label>
			<div class="layui-input-block">
				<input type="text" name="name" value="${row.name }" lay-verify="required" placeholder="请输入教师姓名" autocomplete="off" class="layui-input">
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label">登陆帐号</label>
			<div class="layui-input-block">
				<input type="text" name="account" value="${row.account }" lay-verify="required" placeholder="请输入登陆帐号" autocomplete="off" class="layui-input">
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label">登陆密码</label>
			<div class="layui-input-block">
				<input type="password" name="password" lay-verify="password" placeholder="请输入登陆密码" autocomplete="off" class="layui-input">
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label">登陆密码</label>
			<div class="layui-input-block">
				<input type="password" name="password2" id="password2" placeholder="请再次输入登陆密码" autocomplete="off" class="layui-input">
			</div>
		</div>
		<div class="layui-form-item">
		    <label class="layui-form-label">教师性别${row.sex  }</label>
		    <div class="layui-input-block">
		      <input type="radio" name="sex" value="MALE" title="男" <c:if test="${ 'MALE' eq row.sex }">checked</c:if>>
		      <input type="radio" name="sex" value="FEMALE" title="女" <c:if test="${ 'FEMALE' eq  row.sex }">checked</c:if>>
		      <input type="radio" name="sex" value="UNKNOWN" title="未知" <c:if test="${ 'UNKNOWN' eq row.sex }">checked</c:if>>
		    </div>
		</div>
		<div class="layui-form-item">
		    <label class="layui-form-label">所属班级</label>
		    <div class="layui-input-block">
		      <select name="classes.classesId" lay-verify="required" lay-search="">
		          <option value="">请选择所属班级</option>
		          <c:forEach items="${classes }" var="classes">
			          <option value="${classes.classesId }" <c:if test="${ classes.classesId == row.classes.classesId }">selected="selected"</c:if>>${classes.name }</option>
		          </c:forEach>
		        </select>
		    </div>
		</div>
		<div class="layui-form-item">
		    <label class="layui-form-label">联系电话</label>
		    <div class="layui-input-block">
		      <input type="tel" name="tel" lay-verify="required" value="${row.tel }" placeholder="请输入联系电话" autocomplete="off" class="layui-input">
		    </div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label">出生日期</label>
			<div class="layui-input-block">
				<input type="text" name="born" value="${row.born }" lay-verify="required" placeholder="请选择出生日期" autocomplete="off" class="layui-input" onclick="layui.laydate({elem: this, istime: true, format: 'YYYY-MM-DD'})">
			</div>
		</div>
		<div class="layui-form-item layui-form-text">
			<label class="layui-form-label">联系地址</label>
			<div class="layui-input-block">
				<textarea name="address" lay-verify="required" placeholder="请输入联系地址" class="layui-textarea">${row.address }</textarea>
			</div>
		</div>
		<div class="layui-form-item">
			<div class="layui-input-block">
				<input type="hidden" name="id" value="${row.id }">
				<button class="layui-btn" lay-submit lay-filter="${moduleName }-${moduleAction }">立即提交</button>
				<button type="reset" class="layui-btn layui-btn-primary" id="${moduleName }-${moduleAction }-reset">重置</button>
			</div>
		</div>
	</form>
</div>

<script>
layui.use(['form','laydate'], function() {
	var form = layui.form(),
	$ = layui.jquery;
	form.render();
	
	//自定义验证规则
	  form.verify({
		  name: function(value){
		      if(value.length < 4){
		        return '教师姓名至少得4个字符啊';
		      }
		  },
		  password:function(value){
			  if(value !=0 && value.length < 4){
			        return '密码必须6到12位';
			  }
			  if(value!=$('#password2').val()){
				  return '两次密码不一致';
			  }
		  }
	    
	  });
	//监听提交
	form.on('submit(${moduleName }-${moduleAction })', function(data) {
	//	layer.msg(JSON.stringify(data.field));
		var tmpIndex = layer.load({shade: [0.8, '#393D49']});
	    $.post('${ctx}/console/${moduleName }/${moduleAction}',data.field,function(rst){
	    	console.debug(rst);
	    	layer.close(tmpIndex);
	    	if(!rst){
	    		layer.msg('网络连接错误，请稍后再试。。。', {
	    			icon: 2,
	    			shade: [0.8, '#393D49'],
    			  	anim: 6
    			});
	    		return ;
	    	}
	    	
	    	if('error' == rst.code){
	    		layer.msg(rst.message, {
	    			time:2000,
	    			icon: 2,
	    			shade: [0.8, '#393D49'],
    			  	anim: 6
    			});
	    		return ;
	    	}
	    	layer.confirm('修改成功,留在本页继续添加?',{icon: 3, title:'提示'}
	    	, function(index){
	    		layer.close(index);
	    		$('#${moduleName }-${moduleAction }-reset').trigger('click') ;
	    	}
	    	, function(index){
	    		layer.closeAll();
	    		$('#${moduleName }SearchBtn').trigger('click') ;
	    	});       
	    	
	    },'json');
	
		return false;
	});
});
</script>